//
// Created by zhaog on 31/03/17.
//

#ifndef IMG_SVR_LASTEST_IMG_REQ_HANDLER_H
#define IMG_SVR_LASTEST_IMG_REQ_HANDLER_H

#include "req_handler.h"
#include "meta_struct_types.h"
#include "meta_svr_interface.h"
#include "pic_store_interface.h"

using std::string;
using std::vector;
namespace img_svr{
    struct RecentImgReqBodyStruct{
        int req_id;
        string busi_type;
        string uid;
        int count;
    };

    struct RecentImgReqStruct{
        string staff_id;
        string my_busi;
        string version;
        vector<RecentImgReqBodyStruct> req_body;
    };

    struct RecentImgResBodyStruct{
        int res_id;
        string busi_type;
        string uid;
        int count;
        vector<string> urls;
    };

    struct RecentImgResStruct{
        string staff_id;
        string version;
        vector<RecentImgResBodyStruct> res_body;
    };
    class RecentImgReqHandler:public ReqHandler{
    public:
        void handleRequestImpl(HTTPServerRequest& request, HTTPServerResponse& response);

    private:
        int ParseReq(string& req_json,string& error);
        int GetRecentMetas(set<meta::MetaStruct>& metas);
        int GetImages(vector<pic_store_api::ImgStruct> &imgs);
        void PackResJson(string &json);
        int ShiftMetaToImgStruct(set<meta::MetaStruct> &metas,vector<pic_store_api::ImgStruct> &imgs);
        void WriteFileData(const int& count,const vector<pic_store_api::ImgStruct> &imgs,const string& busi_type,vector<string> &urls);
        void WriteFileData(const vector<pic_store_api::ImgStruct> &imgs);
        RecentImgReqStruct _req_struct;
        RecentImgResStruct _res_struct;
    };
}


#endif //IMG_SVR_LASTEST_IMG_REQ_HANDLER_H
